// es6
// 在类上进行事件触发

const EventEmitter=require("events")

class Person extends EventEmitter{
    constructor(name){
        // 注意点 必须得super（）
        super()
        this.name=name
    }
}

let xiaoming=new Person('xiao')
let lilei=new Person('li')

let persons=[xiaoming,lilei]
persons.forEach(item=>{
    item.on('speak',function(mes){
        console.log(item.name +mes);
        
    })
})
xiaoming.emit("speak",'哈哈')
lilei.emit("speak","呼呼")
